package tests;

import java.util.Random;

import ar.edu.itba.pod.printer.Document;
import ar.edu.itba.pod.printer.PrinterDispatcher;
import ar.edu.itba.pod.printer.impl.SimplePoolPrinterDispatcher;

public class SimpleAsynTest4 {
	
	public static void main(String[] args) {
		
		final int PRUBES = 1;
		long time=0;
		
		System.out.println( "ej 6.2\n SIMPLE POOL PRINTER DISPATCHER");
		
		for(int i=0; i<PRUBES;i++){
			time+=fiftyRequest();
			System.out.println("prueba terminada");
		}
		System.out.println( "Tiempo Promedio:" +  time/PRUBES );
	}
	
	public static long fiftyRequest(){
		final int PRINT_REQUEST = 10;
		final int PAGES = 100;
		final String DOC_NAME = "name";
		
		long start= System.currentTimeMillis();
		PrinterDispatcher dispatcher = new SimplePoolPrinterDispatcher(5);
		
		for(int r=0;r < PRINT_REQUEST; r++){
			Random random = new Random();
			Document document=new Document(PAGES*random.nextInt(15), true, DOC_NAME);
			dispatcher.printDocument(document);
			System.out.print('.');
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		dispatcher.finishPrintRequests();
		return System.currentTimeMillis()-start;
		
	}

}
